#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;



struct item{
	int weight,value;
};



int main(){
	int t,m,y;
	cin>>t>>y>>m;
	item a[m];
	for(int i=0;i<m;i++){
		cin>>a[i].weight>>a[i].value;
//		a[i].value += a[i].weight;
	}
	for(int k=0;k<y;k++){
		int dp[t+1];
		memset(dp,0,sizeof(dp));
		for(int i=1;i<=m;i++)
			for(int j=a[i-1].weight;j<=t;j++)
				dp[j] = max(dp[j],dp[j-a[i-1].weight]+a[i-1].value);
		t += dp[t];
//		cout<<k<<" ";
	}
	cout<<t;
	return 0;
}
